<template>
  <dtDialog
    title="企业认证系统列表"
    :visible.sync="dialogVisible"
    :footerSlot="true"
    @closeDialog="handleCancel"
    @comfirmBtn="onSubmit()"
  >
    <div class="table-container table-fullscreen">
      <dt-table
        v-loading="loading"
        :table-opts="tableOpts"
        :is-show-column="false"
        :maxHeight="300"
      />
    </div>
    <informationFormModel ref="informationFormModel" />
    <informationViewModel ref="informationViewModel" />
  </dtDialog>
</template>

<script>
import informationFormModel from './informationFormModel'
import informationViewModel from './informationViewModel'
import { getSystemResult } from '@/api/information/index'
import { getSystemInfoList } from '@/api/problemPreset/index'

const STATE_SELECT = {
  '0': '未认证',
  '1': '认证中',
  '2': '已认证'
}
let SYSTEM_LIST = []
export default {
  components: { informationFormModel, informationViewModel },
  data() {
    return {
      loading: false,
      tableOpts: {
        configPagination: '1',
        rowKey: 'id',
        firstTableCol: {
          select: false
        },
        indexTableCol: {
          index: false
        },
        tableCol: [
          {
            prop: 'systemId',
            label: '认证系统',
            show: true,
            formatter: (row) => {
              const obj = SYSTEM_LIST.find((item) => {
                return item.systemId == row.systemId
              })
              return obj ? obj.systemName : '-'
            }
          },
          {
            prop: 'state',
            label: '认证状态',
            show: true,
            formatter: (row) => {
              return STATE_SELECT[row.state]
            }
          }
        ],
        tableData: [],
        operator: {
          width: 292,
          operatorBtn: [
            {
              text: '详情',
              size: 'small',
              click: (row, col, cellValue) => { return this.detail(row) }
            },
            {
              text: '重新认证',
              permission: ['INFORMATION_SERVICE_UPDATE_BUTTON'],
              size: 'small',
              click: (row, col, cellValue) => { return this.addAuthentication(row) }
            }
          ]
        }
      },
      dialogVisible: false,
      selectList: [],
      systemList: []
    }
  },
  mounted() {
    getSystemInfoList().then((res) => {
      SYSTEM_LIST = res.data
    })
  },
  methods: {
    addAuthentication(row) {
      this.$refs.informationFormModel.open(row, 1)
    },
    detail(row) {
      this.$refs.informationViewModel.open(row)
    },
    handleCancel() {
      this.tableOpts.tableData = []
    },
    open(id) {
      this.dialogVisible = true
      this.getList(id)
    },
    getList(id) {
      this.loading = true
      getSystemResult(id).then((res) => {
        this.tableOpts.tableData = res.data
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    handleSelection(selection) {
      this.selectList = selection
    },
    onSubmit() {
      if (this.selectList.length > 0) {
        // 提交
      } else {
        this.$dtModal.msgWarning('请至少选择一位业务系统管理人员')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-filter-flex {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  button {
    margin-bottom: 24px;
  }
}
</style>
